package com.tianma315.admin.qa.controller;


import java.util.Arrays;

import com.tianma315.admin.common.utils.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.tianma315.admin.qa.domain.PlasticBottleLineDO;
import com.tianma315.admin.qa.service.PlasticBottleLineService;

/**
 * 
 * <pre>
 * 塑料瓶线
 * </pre>
 * <small> 2019-07-10 09:48:55 | wen</small>
 */
@Controller
@RequestMapping("/qa/plasticBottleLine")
public class PlasticBottleLineController {
	@Autowired
	private PlasticBottleLineService plasticBottleLineService;
	
	@GetMapping()
	@RequiresPermissions("qa:plasticBottleLine:plasticBottleLine")
	String PlasticBottleLine(){
	    return "qa/plasticBottleLine/plasticBottleLine";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("qa:plasticBottleLine:plasticBottleLine")
	public Result<Page<PlasticBottleLineDO>> list(Integer pageNumber, Integer pageSize, PlasticBottleLineDO plasticBottleLineDTO){
		// 查询列表数据
        Page<PlasticBottleLineDO> page = new Page<>(pageNumber, pageSize);
        
        Wrapper<PlasticBottleLineDO> wrapper = new EntityWrapper<PlasticBottleLineDO>(plasticBottleLineDTO);
        page = plasticBottleLineService.selectPage(page, wrapper);
        int total = plasticBottleLineService.selectCount(wrapper);
        page.setTotal(total);
        return Result.ok(page);
	}
	
	@GetMapping("/add")
	@RequiresPermissions("qa:plasticBottleLine:add")
	String add(){
	    return "qa/plasticBottleLine/add";
	}

	@GetMapping("/edit/{plasticBottleLineId}")
	@RequiresPermissions("qa:plasticBottleLine:edit")
	String edit(@PathVariable("plasticBottleLineId") Integer plasticBottleLineId,Model model){
		PlasticBottleLineDO plasticBottleLine = plasticBottleLineService.selectById(plasticBottleLineId);
		model.addAttribute("plasticBottleLine", plasticBottleLine);
	    return "qa/plasticBottleLine/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("qa:plasticBottleLine:add")
	public Result<String> save( PlasticBottleLineDO plasticBottleLine){
		if(plasticBottleLineService.insert(plasticBottleLine)){
			return Result.ok();
		}
		return Result.fail();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("qa:plasticBottleLine:edit")
	public Result<String>  update( PlasticBottleLineDO plasticBottleLine){
		plasticBottleLineService.updateById(plasticBottleLine);
		return Result.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("qa:plasticBottleLine:remove")
	public Result<String>  remove( Integer plasticBottleLineId){
		if(plasticBottleLineService.deleteById(plasticBottleLineId)){
            return Result.ok();
		}
		return Result.fail();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("qa:plasticBottleLine:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Integer[] plasticBottleLineIds){
		plasticBottleLineService.deleteBatchIds(Arrays.asList(plasticBottleLineIds));
		return Result.ok();
	}
	
}
